home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / misc / sci / RARS_Amiga_2.lha / RARS / track.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  3.6 KB  |  103 lines

  1. // TRACK.CPP - Race Course definition 
  2. // by Mitchell E. Timin, State College, PA
  3. // see CAR.H & TRACK.H for class and structure declarations
  4. // This version is for Borland C++, version 3.1, and is for DOS
  5. // This is part of version 0.39 of RARS (Robot Auto Racing Simulation)
  6. // ver. 0.1 release January 12, 1995
  7. // ver. 0.2 1/23/95
  8. // ver. 0.3 2/7/95
  9. // ver. 0.39 3/6/95
  10. // March 9 - build_track() changed to automatically handle degrees or radians
  11.  
  12. #include <fstream.h>
  13. #include <stdlib.h>
  14. #include "track.h"
  15. #include "gi.h"         // needed only for resume_text_display()
  16.  
  17. // array for track data file name:
  18. char trackfile[60];
  19.  
  20. int NSEG;  // number of track segments (see drawpath() in GRAPHICS.CPP)
  21. double X_MAX, Y_MAX; // maximum values that display must show, feet
  22. double width;       // width of track, feet
  23. double TRK_STRT_X; // coordinates of where to start drawing track
  24. double TRK_STRT_Y;  // (feet)
  25. double SCORE_BOARD_X;  // These are in feet, track coordinates
  26. double SCORE_BOARD_Y; // (where the scoreboard is located)
  27. double LDR_BRD_X;      // upper left corner of leader board, feet
  28. double LDR_BRD_Y;
  29. double LOTIX, LOTIY;   // coords of start of "Length of track is ......"
  30. double FINISH;         // fraction of segment 0 prior to finish line
  31. double from_start_to_seg1;  // distance from start/finish line to end of segment
  32.  
  33. // These two arrays describe the outer and inner boundaries of the track:
  34. segment *trackout;
  35. segment *trackin; // Note that the only difference between trackin and
  36.                   // trackout is a "width" feet smaller radius on the curves.
  37.  
  38. // Reads the track definition file and builds the trackin and trackout
  39. // arrays.  If the arc length of the first curve is < 5.0 the units are
  40. // assumed to be radians.  Otherwise they are assumed to be degrees.
  41. void build_track()
  42. {
  43.    ifstream inf(trackfile);
  44.    static int degrees = -1; // will become 1 for degrees, 0 for radians
  45.    int i;
  46.  
  47.    if(!inf) {             // If a filename with no extension was entered,
  48.       for(i=0; i<8; i++)  {            // append .trk and see if that works:
  49.          if(trackfile[i] == '\0')
  50.             break;
  51.          if(trackfile[i] == '.')
  52.             if(trackfile[i+1] == '\0')
  53.                break;
  54.             else  {
  55.                resume_normal_display();
  56.                cout << "There is no track data file.  :(" << endl;
  57.                exit(1);
  58.             }
  59.       }
  60.       trackfile[i++] = '.';
  61.       trackfile[i++] = 't';
  62.       trackfile[i++] = 'r';
  63.       trackfile[i++] = 'k';
  64.       trackfile[i] = '\0';
  65.       inf.open(trackfile);
  66.       if(!inf) {
  67.          resume_normal_display();
  68.          cout << "There is no track data file.  :(" << endl;
  69.          exit(1);
  70.       }
  71.    }
  72.  
  73.    inf >> NSEG >> X_MAX >> Y_MAX >> width;
  74.    inf >> TRK_STRT_X >> TRK_STRT_Y;
  75.    inf >> SCORE_BOARD_X >> SCORE_BOARD_Y;
  76.    inf >> LDR_BRD_X >> LDR_BRD_Y;
  77.    inf >> LOTIX >> LOTIY;
  78.    inf >> FINISH;
  79.    trackout = new segment[NSEG];
  80.    trackin = new segment[NSEG];
  81.  
  82.    for(i=0; i<NSEG; i++)  {
  83.       inf >> trackout[i].radius >> trackout[i].length;
  84.       if(degrees == -1 && trackout[i].radius != 0.0)
  85.          if(trackout[i].length < 5.0)
  86.             degrees = 0;
  87.          else
  88.             degrees = 1;
  89.       if(degrees == 1 && trackout[i].radius != 0.0)
  90.          trackout[i].length /= DEGPRAD;
  91.    }
  92.  
  93.    for(i=0; i<NSEG; i++) {
  94.       if(trackout[i].radius == 0.0)
  95.          trackin[i].radius = trackout[i].radius;
  96.       else
  97.          trackin[i].radius = trackout[i].radius - width;
  98.       trackin[i].length = trackout[i].length;
  99.    }
  100.    // initialize this global variable:
  101.    from_start_to_seg1 = (1.0 - FINISH) * trackout[0].length;
  102. }
  103.